/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.util.*;

/**
 *
 * @author snowangelic
 */
public class Action {
    ArrayList<AttributeValue> attributeList;
    //ArrayList<Cluster> clusterList;
    Point point;
////    Point point;

    Action(){
        attributeList=new  ArrayList<AttributeValue>();
        //clusterList=new ArrayList<Cluster>();
        point=new Point();
    }

    Action(ArrayList<AttributeValue> attributes) {

        point=new Point();
        
        // Parcours de la liste
        Iterator it=attributes.iterator();
        while(it.hasNext()){
           AttributeValue attr=(AttributeValue) it.next();
           attr.setAction(this);
        }
        attributeList=attributes;
        //clusterList=new ArrayList<Cluster>();

    }

    public void setValue(Attribute attribute,Object value){
        for(int i=0;i<attributeList.size();i++){
            if(attributeList.get(i).getAttribute().equals(attribute)){
                attributeList.remove(i);
                i--;
            }
        }
        AttributeValue<Object> attrVal = new AttributeValue<Object>(this,attribute,value);
        attributeList.add(attrVal);
    }

    void removeValue(Attribute attribute) {
        for(int i=0;i<attributeList.size();i++){
            if(attributeList.get(i).getAttribute().equals(attribute)){
                attributeList.remove(i);
                i--;
            }
        }
    }

    void setNormalizedValue(Attribute attribute,Object value){
        Iterator it=attributeList.iterator();
            while(it.hasNext()){
                AttributeValue currentAttrValue=(AttributeValue) it.next();
                if(currentAttrValue.getAttribute().equals(attribute)){
                    currentAttrValue.setNormalizedValue(value);
                }
            }
    }

    /**
     *
     * @param attr
     * @return
     */
    public Object getValue(Attribute attr,boolean normalized){
        Object ret=null;
        // Parcours de la liste à la recherche d'un attributeValue qui point vers attr
        Iterator it=attributeList.iterator();
        while(it.hasNext()){
           AttributeValue attrVal=(AttributeValue) it.next();
           if(attrVal.getAttribute().equals(attr)){ // Si on a trouvé
               ret=attrVal.getValue(normalized);
           }
        }
        return ret;
    }

    public Object getValue(Attribute attr){
        Object ret=null;
        // Parcours de la liste à la recherche d'un attributeValue qui point vers attr
        Iterator it=attributeList.iterator();
        while(it.hasNext()){
           AttributeValue attrVal=(AttributeValue) it.next();
           if(attrVal.getAttribute().equals(attr)){ // Si on a trouvé
               ret=attrVal.getValue(false);
           }
        }
        return ret;
    }

    public void setCoords(float[] coords){
        point.setCoords(coords[0], coords[1], coords[2]);
    }

    float[] getCoords(){
        return point.getCoords();
    }
}
